package com.atguigu.springcloud.cloudsentinelgatewaydevelop.controller;

import com.atguigu.springcloud.cloudsentinelgatewaydevelop.bean.dto.SentinelParamFlowRuleDTO;
import com.atguigu.springcloud.cloudsentinelgatewaydevelop.service.ParamFlowRuleService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;

import java.util.List;

/**
 * 参数流控规则控制器
 *
 * @author Anonymous
 * @version 1.0
 * @since 2022/3/11 13:07
 */
@RequestMapping("paramflow")
@RequiredArgsConstructor
@RestController
public class ParamFlowController {

    private final ParamFlowRuleService paramFlowRuleService;

    @PostMapping("/save")
    public Mono<Integer> save(@RequestBody SentinelParamFlowRuleDTO sentinelParamFlowRuleDTO) {
        return paramFlowRuleService.save(sentinelParamFlowRuleDTO);
    }

    @GetMapping("/find/{id}")
    public Mono<SentinelParamFlowRuleDTO> getById(@PathVariable("id") Long id) {
        return paramFlowRuleService.findById(id);
    }

    @GetMapping("/finds/{applicationName}")
    Mono<List<SentinelParamFlowRuleDTO>> findByApplicationName(@PathVariable("applicationName") String applicationName) {
        return paramFlowRuleService.findByApplicationName(applicationName).collectList();
    }

    @DeleteMapping("/delete/{id}")
    Mono<Integer> deleteById(@PathVariable Long id) {
        return paramFlowRuleService.deleteById(id);
    }

    @DeleteMapping("/deletes/{applicationName}")
    Mono<Integer> deleteByAyApplicationName(@PathVariable("applicationName") String applicationName) {
        return paramFlowRuleService.deleteByAyApplicationName(applicationName);
    }

}
